package org.deng.vertx.web.controller;

import io.vertx.core.Vertx;
import io.vertx.core.http.HttpMethod;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.Session;
import lombok.extern.slf4j.Slf4j;


/**
 * @Author: DengLibin
 * @Date: Create in 2022-05-08 16:41:32
 * @Description:  Session测试
 */
@Slf4j
public class SessionController implements RouterController {

    private Vertx vertx;
    public SessionController(Vertx vertx){
        this.vertx = vertx;
    }
    @Override
    public void configRouter(Router router) {
        log.info("配置SessionController");
        router.route("/session/test").method(HttpMethod.GET).handler(this::sessionTest);
    }
    
    
    /**
     * 获取用户列表
     * @param ctx
     */
    private void sessionTest(RoutingContext ctx){
        log.info("session测试");
        Session session = ctx.session();
        Integer num = session.get("num");
        if(num == null) {
            num = 0;
        }
        num += 1;
        session.put("num", num);
        ctx.end(num+"");
    }
}
